<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>documentName</title>
</head>

<body>
  <ul>
    <li><button id="d1" name="n0">d1</button></li>
    <li><button id="d2" name="n1">d2</button></li>
    <li><button id="d3" name="n2">d3</button></li>
    <li><button id="d4" name="n3">d4</button></li>
    <li><button id="d5" name="n4">d5</button></li>
  </ul>

  <script src="../lib/jquery-3.5.1.min.js"></script>
  <script>
    var delId = 2;

    $("#d" + delId).on("click", function () {
      console.log($(this).html());
    });

    var attrs = "n4";
    $("[name = '" + attrs + "']").on("click", function () {
      // attrs 定义的值点击才有效
      console.log($(this).html());
    });
  </script>
</body>

</html>